package com.example.demo.nuoqi.service.impl;

import com.example.demo.nuoqi.dao.ResumemanagementMapper;
import com.example.demo.nuoqi.pojo.Resumemanagement;
import com.example.demo.nuoqi.service.ResumemanagementService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:Resumemanagement业务层接口实现类
 * @Date 2019/6/14 0:16
 *****/
@Service
public class ResumemanagementServiceImpl implements ResumemanagementService {

    @Autowired
    private ResumemanagementMapper resumemanagementMapper;


    /**
     * Resumemanagement条件+分页查询
     * @param resumemanagement 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public PageInfo<Resumemanagement> findPage(Resumemanagement resumemanagement, int page, int size){
        //分页
        PageHelper.startPage(page,size);
        //搜索条件构建
        Example example = createExample(resumemanagement);
        //执行搜索
        return new PageInfo<Resumemanagement>(resumemanagementMapper.selectByExample(example));
    }

    /**
     * Resumemanagement分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo<Resumemanagement> findPage(int page, int size){
        //静态分页
        PageHelper.startPage(page,size);
        //分页查询
        return new PageInfo<Resumemanagement>(resumemanagementMapper.selectAll());
    }

    /**
     * Resumemanagement条件查询
     * @param resumemanagement
     * @return
     */
    @Override
    public List<Resumemanagement> findList(Resumemanagement resumemanagement){
        //构建查询条件
        Example example = createExample(resumemanagement);
        //根据构建的条件查询数据
        return resumemanagementMapper.selectByExample(example);
    }


    /**
     * Resumemanagement构建查询对象
     * @param resumemanagement
     * @return
     */
    public Example createExample(Resumemanagement resumemanagement){
        Example example=new Example(Resumemanagement.class);
        Example.Criteria criteria = example.createCriteria();
        if(resumemanagement!=null){
            // 
            if(!StringUtils.isEmpty(resumemanagement.getId())){
                    criteria.andEqualTo("id",resumemanagement.getId());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getResumeName())){
                    criteria.andEqualTo("resumeName",resumemanagement.getResumeName());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getUserName())){
                    criteria.andEqualTo("userName",resumemanagement.getUserName());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getUserId())){
                    criteria.andEqualTo("userId",resumemanagement.getUserId());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getBrithTime())){
                    criteria.andEqualTo("brithTime",resumemanagement.getBrithTime());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getNation())){
                    criteria.andEqualTo("nation",resumemanagement.getNation());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getHeight())){
                    criteria.andEqualTo("height",resumemanagement.getHeight());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getPoliticalStatus())){
                    criteria.andEqualTo("politicalStatus",resumemanagement.getPoliticalStatus());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getPhone())){
                    criteria.andEqualTo("phone",resumemanagement.getPhone());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getEmail())){
                    criteria.andEqualTo("email",resumemanagement.getEmail());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getImg())){
                    criteria.andEqualTo("img",resumemanagement.getImg());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getAddress())){
                    criteria.andEqualTo("address",resumemanagement.getAddress());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getProfession())){
                    criteria.andEqualTo("profession",resumemanagement.getProfession());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getProfessionalDirection())){
                    criteria.andEqualTo("professionalDirection",resumemanagement.getProfessionalDirection());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getEducationBackground())){
                    criteria.andEqualTo("educationBackground",resumemanagement.getEducationBackground());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getWorkExperience())){
                    criteria.andEqualTo("workExperience",resumemanagement.getWorkExperience());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getItemExperience())){
                    criteria.andEqualTo("itemExperience",resumemanagement.getItemExperience());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getProfessionalSkill())){
                    criteria.andEqualTo("professionalSkill",resumemanagement.getProfessionalSkill());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getCertificateAwards())){
                    criteria.andEqualTo("certificateAwards",resumemanagement.getCertificateAwards());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getSelfEvaluation())){
                    criteria.andEqualTo("selfEvaluation",resumemanagement.getSelfEvaluation());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getCreateName())){
                    criteria.andEqualTo("createName",resumemanagement.getCreateName());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getCreateId())){
                    criteria.andEqualTo("createId",resumemanagement.getCreateId());
            }
            // 
            if(!StringUtils.isEmpty(resumemanagement.getCreateTime())){
                    criteria.andEqualTo("createTime",resumemanagement.getCreateTime());
            }
        }
        return example;
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(Integer id){
        resumemanagementMapper.deleteByPrimaryKey(id);
    }

    /**
     * 修改Resumemanagement
     * @param resumemanagement
     */
    @Override
    public void update(Resumemanagement resumemanagement){
        resumemanagementMapper.updateByPrimaryKey(resumemanagement);
    }

    /**
     * 增加Resumemanagement
     * @param resumemanagement
     */
    @Override
    public void add(Resumemanagement resumemanagement){
        resumemanagementMapper.insert(resumemanagement);
    }

    /**
     * 根据ID查询Resumemanagement
     * @param id
     * @return
     */
    @Override
    public Resumemanagement findById(Integer id){
        return  resumemanagementMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询Resumemanagement全部数据
     * @return
     */
    @Override
    public List<Resumemanagement> findAll() {
        return resumemanagementMapper.selectAll();
    }

    @Override
    public List<Resumemanagement> findCurrentUserResume(Integer id) {
        Resumemanagement resumemanagement = new Resumemanagement();
        resumemanagement.setCreateId(id);
        Example example = createExample(resumemanagement);
        return resumemanagementMapper.selectByExample(example);
    }


}
